﻿#ifndef __FEATURESELECTION3D_H_
#define __FEATURESELECTION3D_H_

#include "udatabase/dll_cfg.h"
#include "udatabase/interface/ifeatureselection.h"
#include "udatabase/interface/ifeatureclass.h"
#include "kernel/string_def.h"
#include "kernel/OgreIntVector.h"

namespace FD{
	namespace Utility{
		namespace DB{
			/// <summary>
			/// 记录选择集
			/// </summary>
			class FD_DB_Export FeatureSelection3D : public FD::Utility::DB::Interface::IFeatureSelection
			{
			public:		
				/// <summary>
				/// 构造函数
				/// </summary>
				/// <param name="ref_fc">数据集</param>
				/// <returns></returns>	
				FeatureSelection3D(FD::Utility::DB::Interface::IFeatureClass *fs);
				/// <summary>
				/// 析构函数
				/// </summary>
				/// <param name=""></param>
				/// <returns></returns>	
				virtual ~FeatureSelection3D();
			public:
				/// <summary>
				/// 返回构造中传入的FeatureClass
				/// </summary>
				FD::Utility::DB::Interface::IFeatureClass* getFeatureClass();
				/// <summary>
				/// 获得选择集中的记录数
				/// </summary>
				virtual UINT32 getCount() const;
				/// <summary>
				/// 获得选择集中指定索引的记录ID
				/// </summary>
				/// <param name="index">索引</param>
				virtual UINT32 getID(UINT32 index) const;
				/// <summary>
				/// 获得选择集中的记录的所有ID
				/// </summary>
				virtual UINT32 getIDs(UINT32 * ids) const;
				/// <summary>
				/// 找到选择集中的指定ID记录的索引
				/// </summary>
				/// <param name="id">记录的ID</param>
				virtual int32 findID(UINT32 id) const;
				bool existID(UINT32 id);
				/// <summary>
				/// 查询选择集
				/// </summary>
				/// <param name="filter">筛选器</param>
				/// <returns>选择集迭代器指针</returns>
				virtual FD::Utility::DB::Interface::IFeatureIterator* query(FD::Utility::DB::Interface::IQueryFilter* filter) const;
				/// <summary>
				/// 查询选择集
				/// </summary>
				/// <param name="filter">筛选器</param>
				/// <returns>子选择集</returns>
				virtual FD::Utility::DB::Interface::IFeatureSelection* select(FD::Utility::DB::Interface::IQueryFilter* filter) const;
				/// <summary>
				/// 添加记录ID
				/// </summary>
				virtual bool addID(UINT32 id);

				/// <summary>
				/// 添加模型选中的子部件索引
				/// </summary>
				/// <param name="id">模型ID</param>
				/// <param name="subIndexs">子部件索引</param>
				/// <returns>是否添加成功</returns>
				bool addSubIndex(UINT32 id, const FD::Kernel::Int3& subIndex);

				/// <summary>
				/// 判断模型是否存在选中部件
				/// </summary>
				/// <param name="id">模型ID</param>
				/// <param name="subIndexs">子部件的索引集合</param>
				/// <returns>是否添加成功</returns>
				bool existSubIndex(UINT32 id);

				/// <summary>
				/// 获取模型选中的子部件索引
				/// </summary>
				/// <param name="id">模型ID</param>					
				/// <returns>子部件的索引集合，如果值为-1，则没有选中部件</returns>
				const FD::Kernel::Int3& getSubIndex(UINT32 id)const;

				/// <summary>
				/// 批量添加记录id
				/// </summary>
				/// <param name="id">id数组指针</param>
				/// <param name="size">数组大小</param>
				/// <returns>成功添加的个数</returns>
				virtual UINT32 addIDs(UINT32 * id,UINT32 size);

				/// <summary>
				/// 移除指定索引出的指定个数的ID
				/// </summary>
				/// <param name="index">指定索引</param>
				/// <param name="size">指定大小</param>
				/// <returns>成功移除数目</returns>
				virtual UINT32 remove(UINT32 index,UINT32 size);
				/// <summary>
				/// 清除选择集
				/// </summary>
				/// <returns>成功清除的个数</returns>
				virtual UINT32 clear();
				/// <summary>
				/// 求与另一个选择集的交集
				/// </summary>
				/// <param name="set">选择集</param>
				virtual void intersect(const FD::Utility::DB::Interface::IFeatureSelection* set);
				/// <summary>
				/// 求与另一个选择集的补集
				/// </summary>
				/// <param name="set">选择集</param>
				virtual void difference(const FD::Utility::DB::Interface::IFeatureSelection* set);
				/// <summary>
				/// 追加选择集
				/// </summary>
				/// <param name="set">选择集</param>		
				virtual void append(const FD::Utility::DB::Interface::IFeatureSelection* set);
				/// <summary>
				/// 读取数据流
				/// </summary>
				/// <param name="stream">数据流</param>
				void fromStream(FD::Kernel::DataStream &stream);

			protected:					
				String getRestrictionString() const;
			private:
				FeatureSelection3D(FeatureSelection3D & obj);
					
			private:

				mutable vector<UINT32> m_ids;
				set<UINT32> m_set_ids;
				//用于存主键ID和子部件ID
				map<UINT32,FD::Kernel::Int3> mSubIndexMap;
				FD::Utility::DB::Interface::IFeatureClass *m_pFC;
			};

			class FD_DB_Export FeatureSelection3D_Tile : public FD::Utility::DB::Interface::IFeatureSelection
			{
			public:		
				FeatureSelection3D_Tile(){mComponentFlag = false;}

				virtual ~FeatureSelection3D_Tile(){}

			public:
				virtual UINT32 getCount() const;
				virtual UINT32 clear();
			private:
				FeatureSelection3D_Tile(FeatureSelection3D_Tile & obj){}
			public:
				typedef std::set<String> Components;
				Components mComponents;
				bool mComponentFlag;
				FD::Kernel::Math::Vector3 mPoint;
			};

}
}} //End of namespaces

#endif  //_CFEATURE_SELECTION_H_H_
